package com.shaper2.minaapps;

import android.graphics.*;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: danlek
 * Date: 2012-11-01
 * Time: 08:49
 * To change this template use File | Settings | File Templates.
 */
class MyOverlay extends Overlay {
    private Projection projection;
    private List<MyCoordinates> myCoordinatesList;
    public MyOverlay(Projection _projection, List<MyCoordinates> coordinatesList){
        projection = _projection;
        myCoordinatesList = coordinatesList;
    }

    public void draw(Canvas canvas, MapView mapView, boolean shadow){
        Paint dotPaint = new Paint();
        dotPaint.setDither(true);
        dotPaint.setColor(Color.BLUE);
        dotPaint.setStrokeWidth(6);

        Paint myPaint = new Paint();
        myPaint.setDither(true);
        myPaint.setColor(Color.RED);
        myPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        myPaint.setStrokeJoin(Paint.Join.ROUND);
        myPaint.setStrokeCap(Paint.Cap.ROUND);
        myPaint.setStrokeWidth(5);
        GeoPoint gp;
        Point p1 = new Point();
        Point p2 = new Point();
        Path path = new Path();
        gp = new GeoPoint(myCoordinatesList.get(0).getLat(), myCoordinatesList.get(0).getLon());
        projection.toPixels(gp, p1);
        canvas.drawCircle(p1.x, p1.y, 6, dotPaint);
        for (int i = 1; i < myCoordinatesList.size(); i++) {
            gp = new GeoPoint(myCoordinatesList.get(i).getLat(), myCoordinatesList.get(i).getLon());
            projection.toPixels(gp, p2);
            path.moveTo(p2.x, p2.y);
            path.lineTo(p1.x, p1.y);
            p1.x = p2.x;
            p1.y = p2.y;
            canvas.drawCircle(p1.x, p1.y, 6, dotPaint);
        }
        canvas.drawPath(path, myPaint);
    }
}